package move_system

import (
	"confs/gen/common"
	"confs/gen/rpc_protos"
	"gos/services/gactor/actor"
)

// IMoveBehavior 移动系统
type IMoveBehavior interface {
	// StopMoveNotice 停止通知
	StopMoveNotice(serverId string, id int64, curPos *common.Vector2D, status bool, direction *common.Vector2D) error
	// FailNotice 失败通知
	FailNotice(serverId string, data *common.MoveDetailData, reason string) error
	// MovePathNotice 路径点通知
	MovePathNotice(serverId string, id int64, paths []*common.Vector2D, data *common.MoveData) error
	// UpdateMovePathNotice 更新路径点通知
	UpdateMovePathNotice(serverId string, id int64, direction *common.Vector2D, curPos *common.Vector2D, pathPos *common.Vector2D, preCheckTime int64, paths []*common.Vector2D) error
	// SyncEntityData 同步通用数据
	SyncEntityData(serverId string, id int64, data []*common.SyncData) error
}

var MoveBehavior IMoveBehavior

type MoveBehaviorSystem struct{}

func init() {
	MoveBehavior = MoveBehaviorSystem{}
}

// StopMoveNotice 停止移动通知
func (b MoveBehaviorSystem) StopMoveNotice(serverId string, id int64, curPos *common.Vector2D, status bool, direction *common.Vector2D) error {
	return actor.RpcCast(serverId, &rpc_protos.MapRpcStopMoveReq{
		Id:        id,
		Pos:       curPos,
		Status:    status,
		Direction: direction,
	})
}

// FailNotice 失败通知
func (b MoveBehaviorSystem) FailNotice(serverId string, data *common.MoveDetailData, reason string) error {
	return actor.RpcCast(serverId, &rpc_protos.MapRpcMoveFailedReq{
		Data:   data,
		Reason: reason,
	})
}

// MovePathNotice 路径点通知
func (b MoveBehaviorSystem) MovePathNotice(serverId string, id int64, paths []*common.Vector2D, data *common.MoveData) error {
	return actor.RpcCast(serverId, &rpc_protos.MapRpcMovePathReq{
		Id:    id,
		Paths: paths,
		Data:  data,
	})
}

// UpdateMovePathNotice 更新路径点通知
func (b MoveBehaviorSystem) UpdateMovePathNotice(serverId string, id int64, direction *common.Vector2D, curPos *common.Vector2D, pathPos *common.Vector2D, preCheckTime int64, paths []*common.Vector2D) error {
	return actor.RpcCast(serverId, &rpc_protos.MapRpcUpdateMovePathReq{
		Id:           id,
		CurPos:       curPos,
		PathPos:      pathPos,
		UpdateMoveAt: preCheckTime,
		Paths:        paths,
		Direction:    direction,
	})
}

// SyncEntityData 同步通用数据
func (b MoveBehaviorSystem) SyncEntityData(serverId string, id int64, data []*common.SyncData) error {
	return actor.RpcCast(serverId, &rpc_protos.MapRpcSyncDataReq{
		Id:   id,
		Data: data,
	})
}
